<template>
	<view class="hd-pay-code-container">
    <view class="code-content flex-column">
      <view class="code-txt">
        请进行授权登录
      </view>
      <!-- <rh-code v-model="code" :phonenumber="phonenumber"></rh-code> -->
    </view>
		<rh-submit-btn text="立即登录" class-name="special" color="#23994f" :submit-action="wxLogin"></rh-submit-btn>
	</view>
</template>

<script>
	import {getWxUserInfo} from '@/api/common/index.js'
	import {getWxCode, getUrlCode, isWechat, replaceWxUrl} from '@/script/wx-premission.js'
	export default {
		data() {
			return {
				phonenumber: '',
				code: '',
			}
		},
		onLoad(e) {
			let code = getUrlCode('code')
			if(!code){
				getWxCode(location.href)
			}
		},
		methods: {
			wxLogin(){
				return new Promise(async (resolve, reject) => {
					let _self = this
					let code = getUrlCode('code')
					_self.getWxUserInfo(code)
					resolve(true)
				})
			},
			async getWxUserInfo(code) {
				let _self = this
				await getWxUserInfo({code}).then(res => {
					let {isRegister = false, token} = res.data	
					if(isRegister){
						uni.setStorage({
							key: `icar-wxuser`,
							data: {...res.data},
							success: () => {
								_self.$$router.replace({name: 'registerTel'})
							}
						})
					}else{
						uni.setStorage({
							key: `ICarddWx`,
							data: token,
							success: () => {
								_self.$$router.replace({name: 'walletHome'})
							}
						})
					}
				}).finally(() => {
					replaceWxUrl()
				})
			},
		}

	}
</script>
<style lang="scss" scoped>
  // @include fontStyle(#666, 24rpx);
	@mixin fontStyle($color, $size, $weight: 500) {
		color: $color;
		font-size: $size;
		font-weight: $weight;
	}
	.hd-pay-code-container{
		background-color: #fff;
		height: 100vh;
    padding: 80rpx 30rpx 0;
    .code-content{
      .code-txt{
        @include fontStyle(#3D3D3D, 32rpx);
        margin-bottom: 100rpx;
      }
    }
	}

</style>




